package com.zhupanlin.controller;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhupanlin
 * @version 1.0
 * @description: TODO
 * @date 2024/12/15 14:33
 */
@RestController
public class TestController {

    @RequestMapping("/user")
    public String user() {
        // 1.代码中获取用户信息
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        // 2.获取用户信息
        User user = (User) authentication.getPrincipal();
        System.out.println("user = " + user);
        return "user ok";
    }

}
